package com.crl.utils.color
{
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.geom.Matrix;
	
	
	
	/**
	 *  功能简单化,只处理hsb 的hs 值;
	 * @author crl
	 * 
	 */	
	public class HSMixer extends AbstractMixer
	{
		
		/**
		 * saturation 饱和度;
		 */		
		private var saturationColors:Array;
		private var saturationAlphas:Array;
		private var saturationRatios:Array;
		
		
		public function HSMixer()
		{	
		}
		
		override protected function defaults():void{
			/**
			 * 7个梯度颜色; 
			 */		
			colors=[0xFF0000,0xFFFF00,0x00FF00,0x00FFFF,0x0000FF,0xFF00FF,0xFF0000];
			alphas=[100,100,100,100,100,100,100];
			ratios=[0x00,0x2A,0x55,0x7F,0xAA,0xD4,0xFF];
			
			
			saturationColors=[0x808080,0x808080];
			saturationAlphas=[0,100];
			saturationRatios=[0x00,0xFF];
			
		}
		
		
		
		/**
		 * 更新值; 
		 * 
		 */		
		override protected function update(x:int,y:int):void{
//			this._hsb.h=(x/w)*360;
//			this._hsb.s=(h-y)*100/h;
//			
//			
//			this.brightnessBar.hue=this._hsb.h;
//			
			super.update(x,y);
		}
		
		override public function render() : void{
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox(w,h, 0, 0, 0);
			
			var g:Graphics=this.graphics;
			g.clear();
			
			g.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
			g.drawRect(0,0,w, h);
			g.endFill();
			
			
			g=this.mark.graphics;
			g.clear();
			matrix.createGradientBox(w,h,.5*Math.PI);
			g.beginGradientFill(GradientType.LINEAR, saturationColors, saturationAlphas, saturationRatios, matrix);
			g.drawRect(0,0, w, h);
			g.endFill();
			
		}
		
		public function set hsb(value:HSB):void{
			
			this.pointer.x=Math.round(value.h*w/360);
			this.pointer.y=h-Math.round(value.s*h/100);
			
			this.invalidate();
		}
		
	}
}